package com.bosssoft.cart.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    /**
     * 用户登录
     * @param buyerID 用户id password 用户密码
     */
    @RequestMapping("/user/login")
    public String login(String buyerID, String password, Model model, HttpSession session){

        if(!StringUtils.isEmpty(buyerID)&&"123456".equals(password))
        {
            session.setAttribute("loginUser",buyerID);
            return "redirect:/main.html";
        }else{
            model.addAttribute("msg","账号名或密码错误");
            return "index";
        }

    }

    /**
     * 用户登录注销
     * @param session 会话session
     */
    @RequestMapping("/user/loginout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/index.html";
    }

}
